package cn.jinjimi.app.entity.AppConfig;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

import cn.jinjimi.app.bean.SharePrefKeys;
import cn.jinjimi.app.entity.LinkBean;
import cn.jinjimi.app.entity.Notice;
import cn.jinjimi.base.preference.PreferenceManager;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.base.util.StringUtils;
import cn.jinjimi.framework.proguard.Keep;

/**
 * @author zhenhua
 * @date 2018/4/26
 */
@Keep
public class HomeNotices {
    @SerializedName("notices")
    public List<Notice> notices;

    public List<Notice> getNotices() {
        return notices;
    }

    public HomeNotices(List<Notice> list) {
        this.notices = list;
    }
    public static List<Notice> fetchHomeNotices() {
        String data = PreferenceManager.getStringData(SharePrefKeys.PREF_CONFIG_NOTICES);
        if (StringUtils.isNotEmpty(data)) {
            HomeNotices list = GsonUtils.fromJson(data, HomeNotices.class);
            if (list != null) {
                return list.getNotices();
            }
        }
        return new ArrayList<>();
    }

    public static void save(List<Notice> list) {
        PreferenceManager.setData(SharePrefKeys.PREF_CONFIG_NOTICES, new HomeNotices(list));
    }
}
